// For date events

// import { waiting_block } from "./functions.js"; // it`s working
// the file is loaded from a relative address relative to the current file and the name of the static server is used.

const events = staticURL => {
    return {
        '23-02|24-02': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/23febr_2.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '08-03|09-03': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/8march.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '01-05|02-05': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/1may.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '01-05|14-05': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/1-14may.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '05-05|10-05': async date => {
            console.log(`Start event [${date}]`);
            let { eventAudioPlayer } = await import(`${staticURL}/js/events_audio_player.js`);
            let { waiting_block } = await import(`${staticURL}/js/functions.js`);
            let playlist = [['Марк Бернес - Темная ночь', `${staticURL}/music/9may/9-temnaja_noch.mp3`],
            ['Марк Бернес - Журавли', `${staticURL}/music/9may/Bernes_M-Zhuravli.mp3`],
            ['Муслим Магомаев - День Победы', `${staticURL}/music/9may/den_pobedy.mp3`],
            ['Булат Окуджава - Мы за ценой не постоим', `${staticURL}/music/9may/bulat_okudzhava-my_za_cenoj_ne_postoim.mp3`],
            ['Леонид Утёсов - В землянке', `${staticURL}/music/9may/leonid_utjosov_v_zemljanke.mp3`],
            ['Катюша - Академический Ансамбль песни и пляски Российской Армии имени А.В. Александрова', `${staticURL}/music/9may/katjusha-2020-akademicheskij_ansambl_pesni_i_.mp3`],
            ['Кубанский казачий хор - Смуглянка', `${staticURL}/music/9may/nikolaj_ustinov_smugljanka-1944.mp3`],
            ['Валерий Золотухин — Тальяночка', `${staticURL}/music/9may/valerij_zolotukhin_taljanochka-1975.mp3`]]
            if (document.querySelector('.site-menu__wrapper')) {
                eventAudioPlayer(playlist)
            } else {
                waiting_block('.site-menu__wrapper', () => eventAudioPlayer(playlist));
            }
        },
        '09-05|10-05': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/9may.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '12-06|13-06': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/12-06.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        },
        '22-08|23-08': date => {
            console.log(`Start event [${date}]`);
            document.querySelector('.site_header .site_header__logo').insertAdjacentHTML('afterBegin',
                `<video src='${staticURL}/video/flag_rf.webm' autoplay loop muted></video>\n` +
                `<link type='text/css' rel='stylesheet' href='${staticURL}/css/events/28-08[flag_day].css?ver=${(new Date()).getTime()}'/>`
            );
        },
        '15-11|01-01': async (event_date, dt) => {
            console.log(`Start event [${event_date}]`);
            let { newYear } = await import(`${staticURL}/js/functions.js`);
            newYear(staticURL,`${dt.getFullYear()}/11/01`, `${(dt.getFullYear() + 1)}/01/01`, dt);
            
        },
        '01-10|01-03': async date => {
            let { waiting_block, snowInit } = await import(`${staticURL}/js/functions.js`);
            waiting_block('.site_header', async () => {
                console.log(`Start event [${date}]`);
                await import(`${staticURL}/js/jquery-3.7.1.slim.min.js`);
                snowInit(['.site_header'], '.site_header', `${staticURL}/js/snowfall.jquery.js`);
            })
        },
        '-': date => {
            console.log(`Start event [${date}]`);
            const style = `<link type="text/css" href="${staticURL}/css/events/23febr_1.css?ver=${(new Date()).getTime()}" rel='stylesheet'>`;
            document.head.insertAdjacentHTML('beforeend', style);
        }
    }
}
console.log('events module loaded');

export { events }